//
//  MAHomeBtnView.m
//  MateAdv
//
//  Created by 茶 on 2023/9/11.
//

#import "MAHomeBtnView.h"

@interface MAHomeBtnView ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *logoView;
@property (nonatomic, strong) UIImageView *dotView;
@property (nonatomic, strong) UIImageView *tagView;
@property (nonatomic, strong) UIImageView *backView;

@end

@implementation MAHomeBtnView

- (instancetype)init
{
    self = [super init];
    if (self) {
        _showDot = NO;
        [self initInterface];
    }
    return self;
}

- (void)initInterface {
    self.userInteractionEnabled = NO;
    [self addSubview:self.backView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.logoView];
    [self addSubview:self.tagView];
    
    [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-6);
        make.bottom.mas_equalTo(6);
        make.left.mas_equalTo(-10);
        make.right.mas_equalTo(10);
    }];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.ma_offset(26);
        make.centerY.mas_equalTo(0);
    }];
    
    [_logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.ma_offset(-30);
        make.centerY.mas_equalTo(0);
        make.size.ma_offset(80);
    }];
}

+ (void)initDareViewWithButton:(UIButton *)button model:(MAHomeModel *)model{
    UIImageView *backView = [UIImageView initWithName:@"Home_3"];
    backView.userInteractionEnabled = NO;
    [button addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(-6);
        make.bottom.mas_equalTo(6);
        make.left.mas_equalTo(-10);
        make.right.mas_equalTo(10);
    }];
    
    UIImageView *dotView = [UIImageView initWithName:@"Home_Dot"];
    [button addSubview:dotView];
    [dotView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(23);
        make.top.mas_equalTo(10);
    }];
    
    UIImageView *dareView = [UIImageView initWithName:@"Home_Dare"];
    dareView.userInteractionEnabled = NO;
    [button addSubview:dareView];
    [dareView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.ma_offset(24);
        make.top.ma_offset(17);
    }];
    
    UILabel *titleLable = [UILabel new];
    titleLable.userInteractionEnabled = NO;
    titleLable.font = MAFontScaleSemibold(30);
    titleLable.textColor = UIColor.whiteColor;
    titleLable.text = model.title;
    [button addSubview:titleLable];
    [titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.ma_offset(6);
        make.left.ma_offset(24);
    }];
    
    UIImageView *logoView = [UIImageView new];
    [logoView sd_setImageWithURL:[NSURL URLWithString:model.cover]];
    logoView.userInteractionEnabled = NO;
    [button addSubview:logoView];
    [logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.ma_offset(-20);
        make.height.ma_offset(80);
        make.width.ma_offset(100);
    }];
    
}

- (void)setModel:(MAHomeModel *)model {
    _model = model;
    _titleLabel.text = model.title;
    [_logoView sd_setImageWithURL:[NSURL URLWithString:model.cover]];
}

- (void)setTitle:(NSString *)title {
    _titleLabel.text = _title = title;
}

- (void)setImgName:(NSString *)imgName {
    _imgName = imgName;
    _logoView.image = [UIImage imageNamed:imgName];
}

- (void)setBackImgName:(NSString *)backImgName {
    _backImgName = backImgName;
    _backView.image = [UIImage imageNamed:backImgName];
}

- (void)setShowDot:(BOOL)showDot {
    _showDot = showDot;
    if (showDot) {
        [self addSubview:self.dotView];
        [_dotView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(23);
            make.bottom.mas_equalTo(-14);
        }];
    }
}
- (UILabel *)titleLabel {
    if (_titleLabel) return _titleLabel;
    _titleLabel = [UILabel new];
    _titleLabel.font = MAFontScaleSemibold(30);
    _titleLabel.textColor = UIColor.whiteColor;
    return _titleLabel;
}

- (UIImageView *)logoView {
    if (_logoView) return _logoView;
    _logoView = [UIImageView new];
    _logoView.backgroundColor = UIColor.clearColor;
    return _logoView;
}

- (UIImageView *)tagView {
    if (_tagView) return _tagView;
    _tagView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Home_Tag"]];;
    return _tagView;
}

- (UIImageView *)dotView {
    if (_dotView) return _dotView;
    _dotView = [UIImageView initWithName:@"Home_Dot"];
    return _dotView;
}

- (UIImageView *)backView {
    if (_backView) return _backView;
    _backView = [UIImageView new];
    return _backView;
}

@end
